<template>
  <div :class="className" :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from "./mixins/resize";

export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "300px",
    },
  },
  data() {
    return {
      chart: null,
    };
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart.dispose();
    this.chart = null;
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, "macarons");

      this.chart.setOption({
        title: {
          text: this.$t("dashboard.ageDistribution"),
        },
        tooltip: {
          trigger: "axis",
          formatter: "{a} <br/>{b} : {c}",
        },
        legend: {
          left: "center",
          bottom: "10",
          data: ["WEEKLY WRITE ARTICLES"],
        },
        xAxis: {
          type: "category",
          data: ["20-30", "30-40", "40-50", "50-60"],
        },
        yAxis: {
          type: "value",
        },
        series: [
          {
            name: this.$t("dashboard.ageDistribution"),
            type: "line",
            data: [50, 300, 180, 90],
            animationEasing: "cubicInOut",
            animationDuration: 2600,
          },
        ],
      });
    },
  },
};
</script>
